from .io_operation import BasicIo
import threading


class Blowing:
    """
    照明操作
    """
    IDLE = 0
    # CAMMAND_SENDED = 1
    BLOWING_CONTINUE = 2

    def __init__(self, channel_index=None):
        if channel_index is None:
            self.blowing_io = BasicIo("Blowing")
        else:
            self.blowing_io = BasicIo("Blowing_ch%d" % channel_index)
        self.current_step = self.IDLE

    def open(self):
        self.blowing_io.set_true()
        # self.current_step = self.CAMMAND_SENDED
        self.current_step = self.BLOWING_CONTINUE

    def close(self):
        if self.current_step == self.IDLE:
            return

        self.blowing_io.set_false()
        self.current_step = self.IDLE

    def is_open(self):
        if self.current_step == self.IDLE:
            print("处于IDLE状态")
            return False

        return self.blowing_io.read_state()
